<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
error_reporting(E_ERROR | E_PARSE );
// 应用公共文件
//过滤掉特殊字符
function replace_specialChar($strParam){
    $regex = "/\/|\～|\，|\。|\！|\？|\“|\”|\【|\】|\『|\』|\：|\；|\《|\》|\’|\‘|\ |\·|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/";
    return preg_replace($regex,"",$strParam);
}
//随机字符获取方法
function getRandStr($len=10){
    $strs="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
    $str=substr(str_shuffle($strs),mt_rand(0,strlen($strs)-$len-1),$len);
    return $str;
}
//密码加密
function encodePwd($pwd,$str){
    return md5($pwd.md5($str));
}
//获取用户信息
function userinfo($uid){
    $rs=db("user")->where("id='".$uid."'")->find();
    if($rs){
        return $rs["username"];
    }else{
        return "";
    }
}
//获取站点信息
function getsiteinfo(){
    return db("siteinfo")->find();
}
//获取用户所有权限
function getRulelist(){
    //如果是超级管理员获得所有权限
    if(empty(session(config("auth.uid")))){
        return [];
    }else{
        if(in_array(session(config("auth.uid")), config("auth.administrator"))){
            $rs=db("auth_rule")->select();
        }else{
            //获取用户角色组
            $role=db("auth_group_access")->where("uid=".session(config("auth.uid")))->select();
            $str="";
            foreach ($role as $v){
                //获取角色组权限id
                $rule=db("auth_group")->where("id=".$v["group_id"])->field("rules")->find();
                if($rule["rules"]){
                    $str.=$rule["rules"].",";
                } 
            }
            if($str){
                $str=substr($str, 0,-1);
                $rs=db("auth_rule")->where("id in (".$str.")")->select();
            }
            
        }
        $newarr=array();
        foreach($rs as $v){
            $newarr[]=$v["name"];
        }
        return $newarr;
    } 
}

